package com.nickmao.tabwidget;

import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.TextView;
import android.widget.TabHost.TabSpec;

public class TabWidgetActivity extends TabActivity {
    /** Called when the activity is first created. */
	private TabHost tabHost;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_tab);
        tabHost = getTabHost();
        populateTab();
    }
    
    private void populateTab(){
    	Resources res = getResources();
    	
    	populateTabItem(R.drawable.cut_selected,res.getString(R.string.str_tab_item_cut),
    			new Intent(this,TestActivity.class));
    	populateTabItem(R.drawable.lock_selected,res.getString(R.string.str_tab_item_lock),
    			new Intent(this,TestActivity.class));
    	populateTabItem(R.drawable.marker_selected,res.getString(R.string.str_tab_item_marker),
    			new Intent(this,DemoActivity.class));
    }
    
    private void populateTabItem(int imageResourceId,String text,Intent intent){
    	View view = View.inflate(this, R.layout.layout_tab_item, null);
    	((ImageView)view.findViewById(R.id.tab_item_imageview)).setImageResource(imageResourceId);
        ((TextView)view.findViewById(R.id.tab_item_textview)).setText(text);
        
        TabSpec spec = tabHost.newTabSpec(text).setIndicator(view).setContent(intent);
        tabHost.addTab(spec);
    }
}